(function($) {
	$.fn.validata = function(type,message,minLength,maxLength) {
		var _this = this;
		var value = _this[0].value;
        var flog = true;
        
		if(type == "image"){
		    validataFileExt(".jpg|.gif|.png|",2048000);
		}if(type == "logoImage"){
		    validataFileExt(".png|",2048000);
		}else if(type == "blankOrImage" && value){
			validataFileExt(".jpg|.gif|.png|",2048000);
		}else if(type == "audio"){
		    validataFileExt(".mp3|",5120000);
		}else if(type == "video"){
		    validataFileExt(".mp4|",20480000);
		}else if(type == "length"){
	        var length = value ? value.length : 0;
	        if(length < minLength || length > maxLength){
	        	flog = false;
	        }
		}else if(type == "required"){
		    if(!value){
		    	flog = false;
		    }
		}else if(type == "price"){
            flog = /(^[1-9]\d{0,15}$)|^0$|(^(([1-9]\d{0,15})|0)\.\d{1,2}$)/.test(value);
        }else if(type == "zero2one"){
            flog = /^1$|^0$|(^0\.\d{1,10}$)/.test(value);
        }else if(type == "number"){
            flog = /(^[1-9]+\d{0,10}$)|(^0$)/.test(value);
        }else if(type == "mobile"){
            flog = /^1\d{10}$/.test(value);
        }
		errorMessage();
		return flog;
		
		function validataFileExt(fileType,fileSize){
		    var extName = value.substring(value.lastIndexOf(".")).toLowerCase();
		    if(value == null || value == "" || value.lastIndexOf(".") == -1 || fileType.indexOf(extName+"|") == -1){
		    	_this[0].value = "";
		    	flog = false;
		    }else{
			    validataFileSize(fileSize);
		    }
		}
		
		function validataFileSize(fileSize){
		    if(window.ActiveXObject){
		    	/*
				var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
				var file = fileSystem.GetFile (value);
		        if(file.Size > fileSize){
			        flog = false;
			    }*/
		    }else{
		        if(_this[0].files[0].size > fileSize){
			    	_this[0].value = "";
			        flog = false;
			    }
		    }
		}
	    
		function errorMessage(){
		    if(flog){
	            $(_this).parents(".control-group").removeClass("error").find(".help-block").hide();
			}else{
				if(message){
		            $(_this).parents(".control-group").addClass("error").find(".help-block").text(message).show();
				}else{
		            $(_this).parents(".control-group").addClass("error").find(".help-block").show();
				}
			}
		}
	}
})(jQuery);